package com.yqd.lesson.actor.serven

import scala.concurrent.duration._
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
import akka.routing.{BroadcastGroup, FromConfig, RoundRobinGroup, RoundRobinPool}

class Workers extends Actor with ActorLogging{

  context.actorOf(Receiver.props, name = "w1")
  context.actorOf(Receiver.props, name = "w2")
  context.actorOf(Receiver.props, name = "w3")
  var router:ActorRef = context.actorOf(FromConfig.props(),"router3");
  /**val paths = List("/user/workers/w1","/user/workers/w2","/user/workers/w3")
  val router = context.actorOf(RoundRobinGroup(paths).props(),"router")**/

  override def receive: Receive = {
    case msg:String =>
      router ! msg
  }
}


object Workers extends App{
  val system = ActorSystem("akka");

  val sender: ActorRef = system.actorOf(Props[Workers],"workers")

  var count = 0;
  import system.dispatcher
  system.scheduler.schedule(1.second,1.second){
    count += 1;
    println("record:" + count)
    sender ! "" + count
  }

}